﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using MONTRASEC_test.Classes;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace MONTRASEC_test.Classes
{
  public class UtilHelper
  {
    static public String getDateTime(Object dataToConvert)
    {
      //Avant de changer le Calendar en AjaxControlToolkit calendar
      //  return ((DateTime)newDateTime).Year < 1800
      //   ? System.Data.SqlTypes.SqlDateTime.MinValue.Value.ToString() : ((DateTime)newDateTime).ToString();
      //Nouvelle classe
      if (dataToConvert == null)
      {
        return null;
      }
      else
      {
        DateTime newDateTime = new DateTime();

        if ((System.Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag == "en-US") || (System.Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag == "en-GB"))
        {
          return (dataToConvert as String).Substring(3, 2) + "/" + (dataToConvert as String).Substring(0, 2) + "/" + (dataToConvert as String).Substring(6, 4);
        }
        else
        {
          newDateTime = DateTime.Parse(dataToConvert as String);
          return ((DateTime)newDateTime).Year < 1800
             ? null : ((DateTime)newDateTime).ToString();
        }


      }



    }

    static public String getHash(Object dataToConvert)
    {
      if (dataToConvert == null)
        return "";
      else if (dataToConvert.ToString().Trim().Length == 0)
        return "";
      else
        return Hash.Hash.GetHash(dataToConvert.ToString().ToUpper(), Hash.Hash.HashType.SHA512).Substring(0, 50);
    }

    static public String getHash(Object identityName, Object nickname, Object dateOfBirth)
    {
      String PersonalDataConcatenated = null;

      //String.Concat(identityName, nickname, dateOfBirth);

      if (identityName != null)
      { PersonalDataConcatenated += identityName.ToString().Trim(); }

      if (nickname != null)
      { PersonalDataConcatenated += nickname.ToString().Trim(); }

      if (dateOfBirth != null)
      { PersonalDataConcatenated += dateOfBirth.ToString().Trim(); }

      if (PersonalDataConcatenated == null)
        return "";
      else if (PersonalDataConcatenated.ToString().Trim().Length == 0)
        return "";
      else
        return getHash(PersonalDataConcatenated.ToUpper().Trim()).Substring(0, 50);
    }

    static public String getTextForDVMode(DetailsViewMode dvMode)
    {
      String textForDVMode = "";
      switch (dvMode)
      {
        case DetailsViewMode.Edit:
          textForDVMode = "You are editing the Record; Click 'Update' or 'Cancel' button when you've finished";
          break;
        case DetailsViewMode.Insert:
          textForDVMode = "You are creating a new Record; Click 'Insert' or 'Cancel' button when you've finished";
          break;
        case DetailsViewMode.ReadOnly:
          textForDVMode = "You can 'Edit' the current record";
          break;
        default:
          textForDVMode = "You can 'Create a new record' for the selected Entry";
          break;
      }

      return textForDVMode;

    }


    internal static string getSelectedRecord(object currentRecordID)
    {
      String selectedRecord = "";




      selectedRecord = currentRecordID == null ? selectedRecord = "None" : selectedRecord = currentRecordID.ToString();

      return selectedRecord;
    }

    internal static void getInvitationToFillTemplates(BulletedList myBulletedList, String myID)
    {
      myBulletedList.Items.Clear();
      UtilFillInTemplateOnSexualExploitationOfChildren.getInvitationToFillTemplateOnSexualExploitationOfChildren(myBulletedList, myID);

      UtilFillInTheTemplateOnTraffickingInHumanBeings.getInvitationToFillTemplateOnTraffickingInHumanBeings(myBulletedList, myID);
    }


  }
}
